##iP检测
import IPy,platform
from subprocess import Popen,PIPE
import threading


def my_os():  # 获取本机操作系统名称
    if platform.system() == 'Windows':
        p_w = 'n'
    elif platform.system() == 'Linux':
        p_w = 'c'
    return p_w

def ping_ip(os,ip):  # ping指定IP判断主机是否存活
    p = Popen('ping -%s 1 %s' % (os, ip), shell=True,stdin=PIPE,stdout=PIPE,stderr=PIPE,close_fds=True)
    output, errors = p.communicate()
    if p.returncode == 0:
        print(ip,"存活")

def main():
    ip = IPy.IP('192.168.0.0/24')
    ls=[]
    os=my_os()
    for IP in ip:
        t=threading.Thread(target=ping_ip,args=(os,IP))
        #ping_ip(os,IP)
        ls.append(t)
    [ t.start() for t in ls ]

if __name__ == "__main__":
    main()

